package chatclient_01.dialogs;

import chatclient_01.ChatClient;
import java.awt.SystemTray;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.LayoutStyle;

public class OptionsDialog extends JDialog {

  private static final long serialVersionUID = 1L;
  private ChatClient chatClient = null;
  private JButton jButton1;
  private JCheckBox jCheckBox1;

  public OptionsDialog(ChatClient parent, boolean modal) {
    super(parent, modal);
    initComponents();
    this.chatClient = parent;
    if (SystemTray.isSupported()) {
      this.jCheckBox1.setEnabled(true);
    } else {
      this.jCheckBox1.setEnabled(false);
    }
  }

  private void initComponents() {
    this.jCheckBox1 = new JCheckBox();
    this.jButton1 = new JButton();

    setTitle("Options");
    setLocationByPlatform(true);
    setResizable(false);
    addComponentListener(new ComponentAdapter() {

      public void componentShown(ComponentEvent evt) {
        OptionsDialog.this.formComponentShown(evt);
      }
    });
    this.jCheckBox1.setSelected(true);
    this.jCheckBox1.setText("Minimize to System Tray");
    this.jCheckBox1.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent evt) {
        OptionsDialog.this.jCheckBox1ActionPerformed(evt);
      }
    });
    this.jButton1.setText("OK");
    this.jButton1.addActionListener(new ActionListener() {

      public void actionPerformed(ActionEvent evt) {
        OptionsDialog.this.jButton1ActionPerformed(evt);
      }
    });
    GroupLayout layout = new GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(this.jCheckBox1).addContainerGap(80, 32767)).addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup().addContainerGap(139, 32767).addComponent(this.jButton1, -2, 72, -2).addContainerGap()));

    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(this.jCheckBox1).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 65, 32767).addComponent(this.jButton1).addContainerGap()));

    pack();
  }

  private void jCheckBox1ActionPerformed(ActionEvent evt) {
    if (this.jCheckBox1.isSelected()) {
      this.chatClient.setMinimizeToTray(true);
    } else {
      this.chatClient.setMinimizeToTray(false);
    }
  }

  private void formComponentShown(ComponentEvent evt) {
    this.jCheckBox1.setSelected(this.chatClient.isMinimizeToTray());
  }

  private void jButton1ActionPerformed(ActionEvent evt) {
    setVisible(false);
  }
}